package com.proxy.beans;

import com.proxy.factory.ProxyFactory;
import org.springframework.beans.factory.FactoryBean;

/**
 * @author Better Feng
 * @date 2021/8/27 14:37
 */
public class ProxyFactoryBean<T> implements FactoryBean<T> {

    private Class<T> interfaceClass;

    public Class<T> getInterfaceClass() {
        return interfaceClass;
    }

    public void setInterfaceClass(Class<T> interfaceClass) {
        this.interfaceClass = interfaceClass;
    }

    @Override
    public T getObject() throws Exception {
        return new ProxyFactory<>(interfaceClass).createProxyInstance();
    }

    @Override
    public Class<?> getObjectType() {
        return this.interfaceClass;
    }

    @Override
    public boolean isSingleton() {
        return FactoryBean.super.isSingleton();
    }
}
